package heap;

import java.util.*;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 王圆豪
 * Date: 2024-10-07
 * Time: 21:35
 */
public class Test {
    public static void main(String[] args) {
        PriorityQueue<Integer> p = new PriorityQueue<>();
        int k = 3;
        int[] arr = new int[]{6, 4, 9, 5, 36, 2};
        for (int i = 0; i < k; i++) {
            p.add(arr[i]);
        }
        for (int i = k; i < arr.length; i++) {
            if (p.peek() < arr[i]){
                p.poll();
                p.add(arr[i]);
            }
        }
        System.out.println(p.peek());

//        Integer[] arr = new Integer[]{5, 4, 8, 9, 6, 1, 55, 7, 2};
//        Heap<Integer> heap = new Heap<>(arr);
//        heap.createHeap(heap.getElem());
//        heap.add(0);
//        heap.delete();
//        System.out.println(Arrays.toString(heap.getElem()));
    }
}
